<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    protected $table = 'user';
    public $timestamps = false;
    /**
     * 通过user表获得用户详情
     */
    public function detail()
    {
    	 return $this->hasOne('App\Detail', 'user_id');
    }

    /**
     * 通过问题获得用户
     */
    public function getUserByAnswer()
    {
    	return $this->hasOne('App\Answer','user_id');
    }

    /**
     * 判断当前用户对回答的点赞状态
     */
    public function getPraiseStatus()
    {
        // return $this->belongsToMany('App\Answer', 'Apraise', 'user_id', 'answer_id')->withPivot('apraise_status');
        return $this->hasMany('App\Apraise', 'user_id');
    }

    /**
     * 获得当前用户关注的话题
     */
   public function getTopfocus()
   {
        return $this->belongsToMany('App\Topic', 'Topfocus', 'user_id', 'topic_id');
   }

   /**
    * 获得当前用户是否关注该问题
    */
   public function getQuestionfocus()
   {
        return $this->belongsToMany('App\Question', 'questionfocus', 'user_id', 'question_id');
   }

   /**
    * 获得当前用户的所有对问题的回答
    */
   public function getAnswer()
   {

        return $this->hasMany('App\Answer', 'user_id');
   }
   /**
    * 获取用户被关注情况
    */
   public function getUserfocus()
   {
        return $this->hasMany("App\Peoplefocus","other_id");
   }

   //祥
   public function topics()
    {
        return $this->belongsToMany('App\Topic','topfocus','user_id','topic_id');
    }
}
